/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Component = require("grid");
	var Dialog=require("dialog");
	var aw = require("ajaxwrapper");
	var fetchProperties = require("../constant/fetchProperties");
	var gridEvents = require("../handler/gridEvents");
    var instance = {
        initComponent : function (params, widget) {
            var component = new Component({
            	parentNode : ".J-grid",
            	autoRender:false,
            	url : "api/signupregister/queryall",
            	params : function(){
					var subnav = widget.get("subnav");
					var obj = {
						"payFul":subnav.getValue("payFul"),
						"planItemGroup.planItem.destination" : subnav.getValue("destination"),
						"planItemGroup.servicePoint.pkServicePoint" : subnav.getValue("servicePoint"),
						"planItemGroup.planItem.startDate" : subnav.getValue("travelDate").start,
						"planItemGroup.planItem.startDateEnd" : subnav.getValue("travelDate").end,
						fetchProperties:"*,signUpRegister.*,signUpRegister.planItemGroup.*," +
								"signUpRegister.planItemGroup.signUpRoomTypeCounts.*," +
								"signUpRegister.planItemGroup.signUpRoomTypeCounts.roomType.*"
					};
	    			return obj;
				},
				model : {
				 columns  : [{
					 name : "year",
					 label : "年度",
					 format:function(value,row){
						 return "<a class='J-grid-year-plan' style='color:red;'>"+value.substring(0,4)+"</a>";
					 }
				 },{
					 name : "name",
					 label : "计划名称"
				 },{
					 name : "verNumber",
					 label : "版本号"
				 },{
					 name : "dname",
					 label : "目的地"
				 },{
					 name : "startDate",
					 label : "开始日期",
					 format :"date",
					 formatparams:{
							mode:"YYYY-MM-DD"
					 }
				 },{
					 name : "endDate",
					 label : "结束日期",
					 format :"date",
					 formatparams:{
							mode:"YYYY-MM-DD"
					 }
				 },{
					 name : "maxpeople",
					 label : "最多人数",
					 format:function(value,row){
						 if(!row.limitmax){
							 return "不限";
						 }else{
							 return value;
						 }
					 }
				 },{
					 name : "minPeople",
					 label : "最少人数",
					 format:function(value,row){
						 if(!row.limitmin){
							 return "不限";
						 }else{
							 return value;
						 }
					 }
				 },{
					 name : "countMember",
					 label : "已报名人数",
					 format:"detail",
					 formatparams:{
						id:"details",
						handler:function(index,data,rowEle){
							gridEvents.detail(data,widget);
						}
					 }
				 },{
					 name : "signUpStatus.value",
					 label : "状态",
					 format:function(value,row){
						 if(row.countMember==0&&row.signUpStatus==null){
							 return "未报名";
						 }else if(row.countMember>0&&row.signUpStatus==null){
							 return "报名中";
						 }else if(row.countMember>0&&row.signUpStatus!=null&&row.signUpStatus.key=="Confirm"){
							 return "确认";
						 }else{
							 return "";
						 }
					 }
				 },{
					 name:"payFul.value",
					 label:"收费状态",
				 },{
					 name : "operate",
					 label : "操作",
					 format:"button",
						formatparams:[{
							id:"signup",
							text:"报名",
							show:function(value,row){
								if(row.countMember==0&&row.signUpStatus==null){
									 return true;
								 }else if(row.countMember>0&&row.signUpStatus==null){
									 return true;
								 }else if(row.countMember>0&&row.signUpStatus!=null&&row.signUpStatus.key=="Confirm"){
									 return false;
								 }else{
									 return false;
								 }
							},
							handler:function(index,data,rowEle){
								gridEvents.signup(data,widget);
							}
						},{
							id:"confirm",
							text:"确认",
							show:function(value,row){
								if(row.countMember==0&&row.signUpStatus==null){
									 return false;
								 }else if(row.countMember>0&&row.signUpStatus==null){
									 return true;
								 }else if(row.countMember>0&&row.signUpStatus!=null&&row.signUpStatus.key=="Confirm"){
									 return false;
								 }else{
									 return false;
								 }
							},
							handler:function(index,data,rowEle){
								gridEvents.confirm(data,widget);
							}
						}]
				 }]
				}
            });
            widget.set("grid", component);
        }
    };
    module.exports = instance;
});
